package Other.Koko;

import java.util.Arrays;

//875. 爱吃香蕉的珂珂
public class EatingMinSpeed{

    public static void main(String[] args) {
        Solution s = new Solution();
        int[] a = new int[]{312884470};
        int h = 312884469;
        s.minEatingSpeed(a, h);
    }
}



class Solution {
    public int minEatingSpeed(int[] piles, int H) {
        int low = 1;
        int high= -1;
        for(int i :piles){
            high = Math.max(high,i);
        }
       // int ans = Integer.MAX_VALUE;
        while(low<=high){
            int mid = low + (high-low)/2;
            int daysSum = 0;
            for (int i : piles) {
                int days = i/mid;
                days+= i%mid==0?0:1;
                daysSum += days;
            }
            if(daysSum==H){
                 high = mid-1;
            }else if(daysSum>H) low = mid + 1;
            else high = mid-1;
        }
        return low;

    }
}